package com.example.myapplication.slice.slice.slice.slice;

import com.example.myapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.ability.DataAbilityHelper;
import ohos.aafwk.ability.DataAbilityRemoteException;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Text;
import ohos.agp.components.TextField;
import ohos.data.DatabaseHelper;
import ohos.data.dataability.DataAbilityPredicates;
import ohos.data.resultset.ResultSet;
import ohos.utils.net.Uri;
import ohos.utils.system.SystemCapability;

public class resourcePageAbilitySlice extends AbilitySlice {
    private  DataAbilityHelper dataAbilityHelper;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        this.setUIContent(ResourceTable.Layout_resource_ability_main1);

        Text text = (Text) findComponentById(ResourceTable.Id_cold);
        text.setText("");
        //查询信息
        dataAbilityHelper = DataAbilityHelper.creator(this);
        Uri uri = Uri.parse("dataability:///com.example.myapplication.slice.slice.slice.userDataAbility/location");
        String[] colums = {"scene","kind","name","location"};
        DataAbilityPredicates dataAbilityPredicates = new DataAbilityPredicates();
        try {
            ResultSet rs = dataAbilityHelper.query(uri,colums,dataAbilityPredicates);
            //从rs中获取查询结果
            int rowCount = rs.getRowCount();
            if(rowCount>0){
                rs.goToFirstRow();
                do{
                    int scene = rs.getInt(rs.getColumnIndexForName("scene"));
                    String name = rs.getString(1);
                    String kind = rs.getString(1);
                    String location = rs.getString(1);
                    String info = "["+scene+"," + kind + "," + name +","+ location + "]";//
                    text.setText( text.getText()+info);
                }while(rs.goToNextRow());
            }
        } catch (DataAbilityRemoteException e) {
            throw new RuntimeException(e);
        }

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
